#ifndef _SMART_DEVICE_GATEWAY_HEAD_H
#define _SMART_DEVICE_GATEWAY_HEAD_H

#include "udp-net-communication.h"
#include "mqtt-net-communication.h"
#include <thread>
#include <iostream>
#include <thread>
#include <functional>
#include "communication-message.h"
#include <queue>
//互斥锁
#include <mutex>
//条件变量
#include <condition_variable>
#include "communication-worker.h"

using namespace std;

class SmartDeviceGateway
{
public:
	SmartDeviceGateway(const string &uartDevice);
	~SmartDeviceGateway();
	void start(void);
	void udpNetCommunicationRun(void);
	void mqttCommunicationRun(void);
	void communicationHandlerRun(void);
	void wait(void);
	void notify(void);

private:
	UdpNetCommunication *       udpNetCommunication;
	MQTTNetCommunication *      mqttNetCommunication;
	thread *                    udpNetThread;
	thread *                    mqttThread;
	thread *                    communicationHandlerThread;
	queue<CommunicationMessage> messageQueue;
	//互斥锁
	mutex queueMtx;
	mutex mtx;
	//条件变量
	condition_variable  cv;
	CommunicationWorker worker;
};

#endif